/**
 * 
 * @param {Array} menulist 用户信息用于和allRoutes对比
 * @param {Array} allRoutes 用户的完成动态路由表
 * @returns 
 */

let recursionRoutes = (menulist = [], allRoutes = []) => {
    // 用于放置对比之后的路由数据
    let userRoutes = []

    menulist.length > 0 && menulist.forEach(menu => { 
        // 一个 menu ：{id: '1', title: 'glsy', name: '管理首页'}

        allRoutes.forEach(route=>{
            // 一个 route :{"path": "welcome","meta": {"title": "glsy","name": "管理首页","routeName": "welcome"},"id": "welcome"}

            if(menu.title === route.meta.title){
                // 两个标题相等就添加到新数组中
                if(menu.children && menu.children.length > 0){
                    // 如果有children属性需要重新计算
                    route.children = recursionRoutes(menu.children,route.children)
                    // console.log(route.children);
                }

                userRoutes.push(route)
            }
        })
    })
    return userRoutes
}

export default recursionRoutes